package com.examples.sorting;

public class InsertionSort {

	public static int[] selectionSort(int[] arr) {
		int[] tempA = new int[arr.length];
		int temp;
		for (int i = 1; i < arr.length; i++) {
			int j = i;
			int B = arr[i];
			while ((j > 0) && (arr[j - 1] > B)) {

				arr[j] = arr[j - 1];
				j--;
			}
			arr[j] = B;

		}

		return arr;
	}

	public static void main(String[] args) {

		int[] arr = { 10, 9, 2, 3, 5 };// GeneratePrintArray.generateRandomArray(5);
		System.out.println("unsorted array");
		GeneratePrintArray.printArray(arr);
		System.out.println("\n\nsorted array");
		int[] res = selectionSort(arr);
		GeneratePrintArray.printArray(res);
	}
}
